$(function(){
	//登陆按钮绑定回车键
	$(document).keydown(function(event){
		if(event.keyCode==13){
			$("#login").click();
		}
	});
})

//登录
function toLogin(){
	//获取用户名和密码
	var userName = $("#userName").val().trim();
	var password = $("#password").val().trim();
	if(userName=="" ||  password==""){
		alert("用户名或密码不能为空！");
		return ;
	}
		$.ajax({
			url: urlcore + "/api/admin/login",
			type: "POST",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			data:JSON.stringify({
				loginName:userName,
				password:password
			}),
			success:function(data){
				if (data.success == true) {
						//设置cookie
			var domain_url = urlcore.split('://')[1];
			if (domain_url.indexOf(':') > -1) {
				domain_url = domain_url.split(':')[0];
			}else{
				domain_url = domain_url.split('/')[0];
			}
				var str="JSESSIONID="+encodeURIComponent(data.data.token);
				var esp=new Date();
				esp.setTime(esp.getTime()+7*24*60*60*1000);
				str+=";expires="+esp.toGMTString();
				document.cookie=str;
				window.location.href="index.html";
				} else {
					$("#message_login").html(data.msg);
				}
				
			},
			error:function() {
				alert("error");
			}
		});
}